<template>
<!-- 韩佳轩 商品列表 4-5 -->
  <div class="pageshops">
      <div class="center">
      <!-- 今日心动 -->
        <div style="width: 300px;margin-left:-150px;margin-top:40px">
        <img
            src="@/assets/ClassifyImage/柴犬logo.png"
            style="width: 400px;position:absolute"
          /> 
        </div>
       <!-- 模糊查 -->
    <div class="container" style="margin-left:450px;display: inline-block;">
      <input class="input" name="text" type="text" placeholder="请输入商品名称" v-model="commodityName" >
    </div>
      <div style="display:inline-block;margin-left:30px ">
      <button  @click="getShopsList()">查询</button>
      </div>

        <div class="classify_i" >
        <h1
          style="
            text-align: center;
            letter-spacing: 10px;
            font-family: 'Times New Roman', Times, serif;
            font-weight:400;
            
          "
        >
             商品列表大赏
        </h1>
          <el-row>
            <el-col
              :span="6"
              v-for="(item, index) in shopsList"
              :key="index"
              :offset="index % 3 != 0 ? 3 : 0"
              style="height: 380px"
            >
              <el-card :body-style="{ padding: '0px' }">
              <!-- 图片 -->
                <img :src="$imageUrl+'?id='+item.imageId.split(',')[0]" class="image" style="width:200px;height:200px;"/>
                <div style="padding: 14px">
                <span style="font-family: 'Times New Roman', Times, serif;font-size:16px;margin-left:20px">{{ item.commodityName }}</span>
                <!-- 价格 -->
               <p style="margin: 0 0 10px 0; text-align: left; padding-left: 20px">
                <span  style="
                    color: #cc3124;
                    font-size: 20px;
                    font-weight: 700;
                  "
                  >￥{{ item.favorablePrice }}</span
                >

                  <!-- <span>{{ item.name }}</span> -->
                  <!-- 立即查看 -->
                  <div class="bottom clearfix">
                    <el-button type="text" class="button" @click="MainList(item.id)"
                      ><i
                        class="el-icon-caret-right"
                        style="margin-right: 10px"
                      ></i
                      >立即查看</el-button
                    >
                  </div>
                </div>
              </el-card>
            </el-col>
          </el-row>
         <!-- 分页 -->
          <!-- <el-pagination background layout="prev, pager, next" :total="1000" style="margin-top:20px;margin-bottom:30px;text-align:center;">
          </el-pagination> -->
        </div>
      </div>
        </div>
</template>

<script>
export default {
 name:"pageshops",
 data(){
    return{
        //商品id
        id:0,
        //小分类id
        typeId:0,
        //图片id
        imageId:"",
        //优惠价格
        favorablePrice:"",
        //全查数据数组
        shopsList: [],
        //商品名称
        commodityName:"",
    }
 },
 mounted(){
    //声明小分类id
    this.id = this.$route.query.id
    //输出路由的id里是否为空
    // console.log(this.$route)
    this.getShopsList();
 },
   methods: {
    getShopsList(){
   // 根据小分类id查商品列表
      this.$axios.get("/commodity/classify/getCommodity", {
       params:{
        //给后端的小分类id赋值  this.id是循环的的小分类id
        typeId: this.id, 
        //模糊查商品名称
        commodityName: this.commodityName, 
       }
        })
        .then((res) => {
          if (res.data.flag) {       
            this.shopsList = res.data.data;
          }
        })
        .catch((err) => {
          this.myMessage("error", err);
        });
    },
     myMessage(type, message) {
      this.$message({
        message: message,
        type: type,
      });
    },
 //商品列表跳转商品详情页面
    MainList(id) {
      this.$router.push({
        path:'/PageMain',
        query:{
        //后面的id对应的要根据什么id循环查
          id:id
        }
      });
    },
  },
}
</script>

<style scoped>
/*模糊查按钮*/
button, button:focus {
  font-size: 17px;
  padding: 10px 25px;
  border-radius: 0.7rem;
  display: inline-block;
  border: 2px solid rgb(247,247,247);
  border-bottom: 5px solid rgb(247,247,247);
  transform: translate(0, -3px);
  transition: 0.2s;
  transition-timing-function: linear;
}

button:active {
  transform: translate(0, 0);
  border-bottom: 2px solid rgb(50, 50, 50);
}
/*模糊查*/
.container {
  display: flex;
  flex-direction: column;
  gap: 7px;
  position: relative;
}

.container .label {
  font-size: 15px;
  padding-left: 10px;
  position: absolute;
  top: 13px;
  transition: 0.3s;
  pointer-events: none;
}

.input {
  width: 400px;
  height: 45px;
  border: none;
  outline: none;
  padding: 0px 7px;
  border-radius: 6px;
  background-color: transparent;
  box-shadow: 3px 3px 10px rgba(0,0,0,1),
  -1px -1px 6px rgba(22, 21, 21, 0.4);
}

.input:focus {
  border: 2px solid transparent;
  color: #fff;
  box-shadow: 3px 3px 10px rgba(0,0,0,1),
  -1px -1px 6px rgba(255, 255, 255, 0.4),
  inset 3px 3px 10px rgba(0,0,0,1),
  inset -1px -1px 6px rgba(255, 255, 255, 0.4);
}

.input:focus.input::placeholder {
  transition: 0.3s;
  opacity: 0;
}

.input:focus + .label {
  transition: 0.3s;
  padding-left: 2px;
  transform: translateY(-35px);
}
.pageClassify {
  background-color: #fff;
  overflow: hidden;
}
.el-carousel__item h3 {
  color: #475669;
  font-size: 14px;
  opacity: 0.75;
  line-height: 500px;
  margin: 0;
}
.el-carousel__item:nth-child(2n) {
  background-color: #beb22b;
}
.el-carousel__item:nth-child(2n + 1) {
  background-color: #d3dce6;
}

/*页面居中*/
.center {
  width: 80%;
  margin: 0 auto;
}
/*中间图片*/
.center_img {
  width: 100%;
  height: 200px;
}
.center_img > div {
  width: 50%;
  display: inline-block;
}
.center_img img {
  height: 220px;
  display: inline-block;
}
/*特色DIy*/
.el-carousel__mask {
  background: transparent;
}
.characteristic {
  margin-top: 30px;
  padding-top: 10px;
  border-radius: 50px;
}
.characteristic_text {
  position: absolute;
  left: 24.5%;
  width: 240px;
  height: 70px;
  background: linear-gradient(
    to bottom,
    rgba(255, 255, 255, 0) 0%,
    rgba(255, 255, 255, 1) 50%,
    rgba(255, 255, 255, 1) 100%
  );
}
.characteristic_i {
  margin: 0 auto;
  height: 330px;
  width: 240px;
  box-shadow: 8px 8px 10px #475669;
  border-radius: 2px;
  background: #fff;
}
/*分类*/
.time {
  font-size: 13px;
  color: #999;
}

.bottom {
  margin-top: 13px;
  line-height: 12px;
}

.button {
  padding: 0;
  float: left;
  font-weight: 700;
  color: #ffcd00;
}

.image {
  width: 100%;
  display: block;
}


.clearfix:before,
.clearfix:after {
  display: table;
  content: "";
}

.clearfix:after {
  clear: both;
}
.classify_i {
  width: 60%;
  margin: 0 auto;
}

</style>
